<?php
	/**
	 * The abstract TablePortfolioCategoryGen class defined here is
	 * code-generated and contains all the basic CRUD-type functionality as well as
	 * basic methods to handle relationships and index-based loading.
	 *
	 * To use, you should use the TablePortfolioCategory subclass which
	 * extends this TablePortfolioCategoryGen class.
	 *
	 * Because subsequent re-code generations will overwrite any changes to this
	 * file, you should leave this file unaltered to prevent yourself from losing
	 * any information or code changes.  All customizations should be done by
	 * overriding existing or implementing new methods, properties and variables
	 * in the TablePortfolioCategory class.
	 * 
	 * @package My Application
	 * @subpackage GeneratedDataObjects
	 * @property-read integer $Id the value for intId (Read-Only PK)
	 * @property integer $CategoryId the value for intCategoryId (Unique)
	 * @property integer $ParentCategoryId the value for intParentCategoryId 
	 * @property string $TitleEn the value for strTitleEn 
	 * @property string $TitleJp the value for strTitleJp 
	 * @property string $KeywordEn the value for strKeywordEn 
	 * @property string $KeywordJp the value for strKeywordJp 
	 * @property string $Enable the value for strEnable 
	 * @property QDateTime $RegisterDate the value for dttRegisterDate (Not Null)
	 * @property QDateTime $UpdateDate the value for dttUpdateDate 
	 * @property-read boolean $__Restored whether or not this object was restored from the database (as opposed to created new)
	 */
	class TablePortfolioCategoryGen extends QBaseClass {

		///////////////////////////////////////////////////////////////////////
		// PROTECTED MEMBER VARIABLES and TEXT FIELD MAXLENGTHS (if applicable)
		///////////////////////////////////////////////////////////////////////
		
		/**
		 * Protected member variable that maps to the database PK Identity column table_portfolio_category.id
		 * @var integer intId
		 */
		protected $intId;
		const IdDefault = 0;


		/**
		 * Protected member variable that maps to the database column table_portfolio_category.category_id
		 * @var integer intCategoryId
		 */
		protected $intCategoryId;
		const CategoryIdDefault = 0;


		/**
		 * Protected member variable that maps to the database column table_portfolio_category.parent_category_id
		 * @var integer intParentCategoryId
		 */
		protected $intParentCategoryId;
		const ParentCategoryIdDefault = 0;


		/**
		 * Protected member variable that maps to the database column table_portfolio_category.title_en
		 * @var string strTitleEn
		 */
		protected $strTitleEn;
		const TitleEnMaxLength = 200;
		const TitleEnDefault = null;


		/**
		 * Protected member variable that maps to the database column table_portfolio_category.title_jp
		 * @var string strTitleJp
		 */
		protected $strTitleJp;
		const TitleJpMaxLength = 200;
		const TitleJpDefault = null;


		/**
		 * Protected member variable that maps to the database column table_portfolio_category.keyword_en
		 * @var string strKeywordEn
		 */
		protected $strKeywordEn;
		const KeywordEnMaxLength = 200;
		const KeywordEnDefault = null;


		/**
		 * Protected member variable that maps to the database column table_portfolio_category.keyword_jp
		 * @var string strKeywordJp
		 */
		protected $strKeywordJp;
		const KeywordJpMaxLength = 200;
		const KeywordJpDefault = null;


		/**
		 * Protected member variable that maps to the database column table_portfolio_category.enable
		 * @var string strEnable
		 */
		protected $strEnable;
		const EnableMaxLength = 1;
		const EnableDefault = null;


		/**
		 * Protected member variable that maps to the database column table_portfolio_category.register_date
		 * @var QDateTime dttRegisterDate
		 */
		protected $dttRegisterDate;
		const RegisterDateDefault = null;


		/**
		 * Protected member variable that maps to the database column table_portfolio_category.update_date
		 * @var QDateTime dttUpdateDate
		 */
		protected $dttUpdateDate;
		const UpdateDateDefault = null;


		/**
		 * Protected array of virtual attributes for this object (e.g. extra/other calculated and/or non-object bound
		 * columns from the run-time database query result for this object).  Used by InstantiateDbRow and
		 * GetVirtualAttribute.
		 * @var string[] $__strVirtualAttributeArray
		 */
		protected $__strVirtualAttributeArray = array();

		/**
		 * Protected internal member variable that specifies whether or not this object is Restored from the database.
		 * Used by Save() to determine if Save() should perform a db UPDATE or INSERT.
		 * @var bool __blnRestored;
		 */
		protected $__blnRestored;




		///////////////////////////////
		// PROTECTED MEMBER OBJECTS
		///////////////////////////////





		///////////////////////////////
		// CLASS-WIDE LOAD AND COUNT METHODS
		///////////////////////////////

		/**
		 * Static method to retrieve the Database object that owns this class.
		 * @return QDatabaseBase reference to the Database object that can query this class
		 */
		public static function GetDatabase() {
			return QApplication::$Database[1];
		}

		/**
		 * Load a TablePortfolioCategory from PK Info
		 * @param integer $intId
		 * @param QQClause[] $objOptionalClauses additional optional QQClause objects for this query
		 * @return TablePortfolioCategory
		 */
		public static function Load($intId, $objOptionalClauses = null) {
			// Use QuerySingle to Perform the Query
			return TablePortfolioCategory::QuerySingle(
				QQ::AndCondition(
					QQ::Equal(QQN::TablePortfolioCategory()->Id, $intId)
				),
				$objOptionalClauses
			);
		}

		/**
		 * Load all TablePortfolioCategories
		 * @param QQClause[] $objOptionalClauses additional optional QQClause objects for this query
		 * @return TablePortfolioCategory[]
		 */
		public static function LoadAll($objOptionalClauses = null) {
			if (func_num_args() > 1) {
				throw new QCallerException("LoadAll must be called with an array of optional clauses as a single argument");
			}
			// Call TablePortfolioCategory::QueryArray to perform the LoadAll query
			try {
				return TablePortfolioCategory::QueryArray(QQ::All(), $objOptionalClauses);
			} catch (QCallerException $objExc) {
				$objExc->IncrementOffset();
				throw $objExc;
			}
		}

		/**
		 * Count all TablePortfolioCategories
		 * @return int
		 */
		public static function CountAll() {
			// Call TablePortfolioCategory::QueryCount to perform the CountAll query
			return TablePortfolioCategory::QueryCount(QQ::All());
		}




		///////////////////////////////
		// QCUBED QUERY-RELATED METHODS
		///////////////////////////////

		/**
		 * Internally called method to assist with calling Qcubed Query for this class
		 * on load methods.
		 * @param QQueryBuilder &$objQueryBuilder the QueryBuilder object that will be created
		 * @param QQCondition $objConditions any conditions on the query, itself
		 * @param QQClause[] $objOptionalClausees additional optional QQClause object or array of QQClause objects for this query
		 * @param mixed[] $mixParameterArray a array of name-value pairs to perform PrepareStatement with (sending in null will skip the PrepareStatement step)
		 * @param boolean $blnCountOnly only select a rowcount
		 * @return string the query statement
		 */
		protected static function BuildQueryStatement(&$objQueryBuilder, QQCondition $objConditions, $objOptionalClauses, $mixParameterArray, $blnCountOnly) {
			// Get the Database Object for this Class
			$objDatabase = TablePortfolioCategory::GetDatabase();

			// Create/Build out the QueryBuilder object with TablePortfolioCategory-specific SELET and FROM fields
			$objQueryBuilder = new QQueryBuilder($objDatabase, 'table_portfolio_category');
			TablePortfolioCategory::GetSelectFields($objQueryBuilder);
			$objQueryBuilder->AddFromItem('table_portfolio_category');

			// Set "CountOnly" option (if applicable)
			if ($blnCountOnly)
				$objQueryBuilder->SetCountOnlyFlag();

			// Apply Any Conditions
			if ($objConditions)
				try {
					$objConditions->UpdateQueryBuilder($objQueryBuilder);
				} catch (QCallerException $objExc) {
					$objExc->IncrementOffset();
					throw $objExc;
				}

			// Iterate through all the Optional Clauses (if any) and perform accordingly
			if ($objOptionalClauses) {
				if ($objOptionalClauses instanceof QQClause)
					$objOptionalClauses->UpdateQueryBuilder($objQueryBuilder);
				else if (is_array($objOptionalClauses))
					foreach ($objOptionalClauses as $objClause)
						$objClause->UpdateQueryBuilder($objQueryBuilder);
				else
					throw new QCallerException('Optional Clauses must be a QQClause object or an array of QQClause objects');
			}

			// Get the SQL Statement
			$strQuery = $objQueryBuilder->GetStatement();

			// Prepare the Statement with the Query Parameters (if applicable)
			if ($mixParameterArray) {
				if (is_array($mixParameterArray)) {
					if (count($mixParameterArray))
						$strQuery = $objDatabase->PrepareStatement($strQuery, $mixParameterArray);

					// Ensure that there are no other Unresolved Named Parameters
					if (strpos($strQuery, chr(QQNamedValue::DelimiterCode) . '{') !== false)
						throw new QCallerException('Unresolved named parameters in the query');
				} else
					throw new QCallerException('Parameter Array must be an array of name-value parameter pairs');
			}

			// Return the Objects
			return $strQuery;
		}

		/**
		 * Static Qcubed Query method to query for a single TablePortfolioCategory object.
		 * Uses BuildQueryStatment to perform most of the work.
		 * @param QQCondition $objConditions any conditions on the query, itself
		 * @param QQClause[] $objOptionalClausees additional optional QQClause objects for this query
		 * @param mixed[] $mixParameterArray a array of name-value pairs to perform PrepareStatement with
		 * @return TablePortfolioCategory the queried object
		 */
		public static function QuerySingle(QQCondition $objConditions, $objOptionalClauses = null, $mixParameterArray = null) {
			// Get the Query Statement
			try {
				$strQuery = TablePortfolioCategory::BuildQueryStatement($objQueryBuilder, $objConditions, $objOptionalClauses, $mixParameterArray, false);
			} catch (QCallerException $objExc) {
				$objExc->IncrementOffset();
				throw $objExc;
			}
			
			// Perform the Query, Get the First Row, and Instantiate a new TablePortfolioCategory object
			$objDbResult = $objQueryBuilder->Database->Query($strQuery);
			
			// Do we have to expand anything?
			if ($objQueryBuilder->ExpandAsArrayNodes) {
				$objToReturn = array();
				while ($objDbRow = $objDbResult->GetNextRow()) {
					$objItem = TablePortfolioCategory::InstantiateDbRow($objDbRow, null, $objQueryBuilder->ExpandAsArrayNodes, $objToReturn, $objQueryBuilder->ColumnAliasArray);
					if ($objItem)
						$objToReturn[] = $objItem;					
				}			
				// Since we only want the object to return, lets return the object and not the array.
				return $objToReturn[0];
			} else {
				// No expands just return the first row
				$objToReturn = null;
				while ($objDbRow = $objDbResult->GetNextRow())
					$objToReturn = TablePortfolioCategory::InstantiateDbRow($objDbRow, null, null, null, $objQueryBuilder->ColumnAliasArray);
			}
			
			return $objToReturn;
		}

		/**
		 * Static Qcubed Query method to query for an array of TablePortfolioCategory objects.
		 * Uses BuildQueryStatment to perform most of the work.
		 * @param QQCondition $objConditions any conditions on the query, itself
		 * @param QQClause[] $objOptionalClausees additional optional QQClause objects for this query
		 * @param mixed[] $mixParameterArray a array of name-value pairs to perform PrepareStatement with
		 * @return TablePortfolioCategory[] the queried objects as an array
		 */
		public static function QueryArray(QQCondition $objConditions, $objOptionalClauses = null, $mixParameterArray = null) {
			// Get the Query Statement
			try {
				$strQuery = TablePortfolioCategory::BuildQueryStatement($objQueryBuilder, $objConditions, $objOptionalClauses, $mixParameterArray, false);
			} catch (QCallerException $objExc) {
				$objExc->IncrementOffset();
				throw $objExc;
			}

			// Perform the Query and Instantiate the Array Result
			$objDbResult = $objQueryBuilder->Database->Query($strQuery);
			return TablePortfolioCategory::InstantiateDbResult($objDbResult, $objQueryBuilder->ExpandAsArrayNodes, $objQueryBuilder->ColumnAliasArray);
		}

		/**
		 * Static Qcubed Query method to query for a count of TablePortfolioCategory objects.
		 * Uses BuildQueryStatment to perform most of the work.
		 * @param QQCondition $objConditions any conditions on the query, itself
		 * @param QQClause[] $objOptionalClausees additional optional QQClause objects for this query
		 * @param mixed[] $mixParameterArray a array of name-value pairs to perform PrepareStatement with
		 * @return integer the count of queried objects as an integer
		 */
		public static function QueryCount(QQCondition $objConditions, $objOptionalClauses = null, $mixParameterArray = null) {
			// Get the Query Statement
			try {
				$strQuery = TablePortfolioCategory::BuildQueryStatement($objQueryBuilder, $objConditions, $objOptionalClauses, $mixParameterArray, true);
			} catch (QCallerException $objExc) {
				$objExc->IncrementOffset();
				throw $objExc;
			}

			// Perform the Query and return the row_count
			$objDbResult = $objQueryBuilder->Database->Query($strQuery);

			// Figure out if the query is using GroupBy
			$blnGrouped = false;

			if ($objOptionalClauses) foreach ($objOptionalClauses as $objClause) {
				if ($objClause instanceof QQGroupBy) {
					$blnGrouped = true;
					break;
				}
			}

			if ($blnGrouped)
				// Groups in this query - return the count of Groups (which is the count of all rows)
				return $objDbResult->CountRows();
			else {
				// No Groups - return the sql-calculated count(*) value
				$strDbRow = $objDbResult->FetchRow();
				return QType::Cast($strDbRow[0], QType::Integer);
			}
		}

		public static function QueryArrayCached(QQCondition $objConditions, $objOptionalClauses = null, $mixParameterArray = null, $blnForceUpdate = false) {
			// Get the Database Object for this Class
			$objDatabase = TablePortfolioCategory::GetDatabase();

			$strQuery = TablePortfolioCategory::BuildQueryStatement($objQueryBuilder, $objConditions, $objOptionalClauses, $mixParameterArray, false);
			
			$objCache = new QCache('qquery/tableportfoliocategory', $strQuery);
			$cacheData = $objCache->GetData();
			
			if (!$cacheData || $blnForceUpdate) {
				$objDbResult = $objQueryBuilder->Database->Query($strQuery);
				$arrResult = TablePortfolioCategory::InstantiateDbResult($objDbResult, $objQueryBuilder->ExpandAsArrayNodes, $objQueryBuilder->ColumnAliasArray);
				$objCache->SaveData(serialize($arrResult));
			} else {
				$arrResult = unserialize($cacheData);
			}
			
			return $arrResult;
		}

		/**
		 * Updates a QQueryBuilder with the SELECT fields for this TablePortfolioCategory
		 * @param QQueryBuilder $objBuilder the Query Builder object to update
		 * @param string $strPrefix optional prefix to add to the SELECT fields
		 */
		public static function GetSelectFields(QQueryBuilder $objBuilder, $strPrefix = null) {
			if ($strPrefix) {
				$strTableName = $strPrefix;
				$strAliasPrefix = $strPrefix . '__';
			} else {
				$strTableName = 'table_portfolio_category';
				$strAliasPrefix = '';
			}

			$objBuilder->AddSelectItem($strTableName, 'id', $strAliasPrefix . 'id');
			$objBuilder->AddSelectItem($strTableName, 'category_id', $strAliasPrefix . 'category_id');
			$objBuilder->AddSelectItem($strTableName, 'parent_category_id', $strAliasPrefix . 'parent_category_id');
			$objBuilder->AddSelectItem($strTableName, 'title_en', $strAliasPrefix . 'title_en');
			$objBuilder->AddSelectItem($strTableName, 'title_jp', $strAliasPrefix . 'title_jp');
			$objBuilder->AddSelectItem($strTableName, 'keyword_en', $strAliasPrefix . 'keyword_en');
			$objBuilder->AddSelectItem($strTableName, 'keyword_jp', $strAliasPrefix . 'keyword_jp');
			$objBuilder->AddSelectItem($strTableName, 'enable', $strAliasPrefix . 'enable');
			$objBuilder->AddSelectItem($strTableName, 'register_date', $strAliasPrefix . 'register_date');
			$objBuilder->AddSelectItem($strTableName, 'update_date', $strAliasPrefix . 'update_date');
		}



		///////////////////////////////
		// INSTANTIATION-RELATED METHODS
		///////////////////////////////

		/**
		 * Instantiate a TablePortfolioCategory from a Database Row.
		 * Takes in an optional strAliasPrefix, used in case another Object::InstantiateDbRow
		 * is calling this TablePortfolioCategory::InstantiateDbRow in order to perform
		 * early binding on referenced objects.
		 * @param DatabaseRowBase $objDbRow
		 * @param string $strAliasPrefix
		 * @param string $strExpandAsArrayNodes
		 * @param QBaseClass $arrPreviousItem
		 * @param string[] $strColumnAliasArray
		 * @return TablePortfolioCategory
		*/
		public static function InstantiateDbRow($objDbRow, $strAliasPrefix = null, $strExpandAsArrayNodes = null, $arrPreviousItems = null, $strColumnAliasArray = array()) {
			// If blank row, return null
			if (!$objDbRow) {
				return null;
			}

			// Create a new instance of the TablePortfolioCategory object
			$objToReturn = new TablePortfolioCategory();
			$objToReturn->__blnRestored = true;

			$strAliasName = array_key_exists($strAliasPrefix . 'id', $strColumnAliasArray) ? $strColumnAliasArray[$strAliasPrefix . 'id'] : $strAliasPrefix . 'id';
			$objToReturn->intId = $objDbRow->GetColumn($strAliasName, 'Integer');
			$strAliasName = array_key_exists($strAliasPrefix . 'category_id', $strColumnAliasArray) ? $strColumnAliasArray[$strAliasPrefix . 'category_id'] : $strAliasPrefix . 'category_id';
			$objToReturn->intCategoryId = $objDbRow->GetColumn($strAliasName, 'Integer');
			$strAliasName = array_key_exists($strAliasPrefix . 'parent_category_id', $strColumnAliasArray) ? $strColumnAliasArray[$strAliasPrefix . 'parent_category_id'] : $strAliasPrefix . 'parent_category_id';
			$objToReturn->intParentCategoryId = $objDbRow->GetColumn($strAliasName, 'Integer');
			$strAliasName = array_key_exists($strAliasPrefix . 'title_en', $strColumnAliasArray) ? $strColumnAliasArray[$strAliasPrefix . 'title_en'] : $strAliasPrefix . 'title_en';
			$objToReturn->strTitleEn = $objDbRow->GetColumn($strAliasName, 'VarChar');
			$strAliasName = array_key_exists($strAliasPrefix . 'title_jp', $strColumnAliasArray) ? $strColumnAliasArray[$strAliasPrefix . 'title_jp'] : $strAliasPrefix . 'title_jp';
			$objToReturn->strTitleJp = $objDbRow->GetColumn($strAliasName, 'VarChar');
			$strAliasName = array_key_exists($strAliasPrefix . 'keyword_en', $strColumnAliasArray) ? $strColumnAliasArray[$strAliasPrefix . 'keyword_en'] : $strAliasPrefix . 'keyword_en';
			$objToReturn->strKeywordEn = $objDbRow->GetColumn($strAliasName, 'VarChar');
			$strAliasName = array_key_exists($strAliasPrefix . 'keyword_jp', $strColumnAliasArray) ? $strColumnAliasArray[$strAliasPrefix . 'keyword_jp'] : $strAliasPrefix . 'keyword_jp';
			$objToReturn->strKeywordJp = $objDbRow->GetColumn($strAliasName, 'VarChar');
			$strAliasName = array_key_exists($strAliasPrefix . 'enable', $strColumnAliasArray) ? $strColumnAliasArray[$strAliasPrefix . 'enable'] : $strAliasPrefix . 'enable';
			$objToReturn->strEnable = $objDbRow->GetColumn($strAliasName, 'VarChar');
			$strAliasName = array_key_exists($strAliasPrefix . 'register_date', $strColumnAliasArray) ? $strColumnAliasArray[$strAliasPrefix . 'register_date'] : $strAliasPrefix . 'register_date';
			$objToReturn->dttRegisterDate = $objDbRow->GetColumn($strAliasName, 'DateTime');
			$strAliasName = array_key_exists($strAliasPrefix . 'update_date', $strColumnAliasArray) ? $strColumnAliasArray[$strAliasPrefix . 'update_date'] : $strAliasPrefix . 'update_date';
			$objToReturn->dttUpdateDate = $objDbRow->GetColumn($strAliasName, 'DateTime');

			if (isset($arrPreviousItems) && is_array($arrPreviousItems)) {
				foreach ($arrPreviousItems as $objPreviousItem) {
					if ($objToReturn->Id != $objPreviousItem->Id) {
						continue;
					}

					// complete match - all primary key columns are the same
					return null;
				}
			}

			// Instantiate Virtual Attributes
			foreach ($objDbRow->GetColumnNameArray() as $strColumnName => $mixValue) {
				$strVirtualPrefix = $strAliasPrefix . '__';
				$strVirtualPrefixLength = strlen($strVirtualPrefix);
				if (substr($strColumnName, 0, $strVirtualPrefixLength) == $strVirtualPrefix)
					$objToReturn->__strVirtualAttributeArray[substr($strColumnName, $strVirtualPrefixLength)] = $mixValue;
			}

			// Prepare to Check for Early/Virtual Binding
			if (!$strAliasPrefix)
				$strAliasPrefix = 'table_portfolio_category__';




			return $objToReturn;
		}

		/**
		 * Instantiate an array of TablePortfolioCategories from a Database Result
		 * @param DatabaseResultBase $objDbResult
		 * @param string $strExpandAsArrayNodes
		 * @param string[] $strColumnAliasArray
		 * @return TablePortfolioCategory[]
		 */
		public static function InstantiateDbResult(QDatabaseResultBase $objDbResult, $strExpandAsArrayNodes = null, $strColumnAliasArray = null) {
			$objToReturn = array();
			
			if (!$strColumnAliasArray)
				$strColumnAliasArray = array();

			// If blank resultset, then return empty array
			if (!$objDbResult)
				return $objToReturn;

			// Load up the return array with each row
			if ($strExpandAsArrayNodes) {
				$objToReturn = array();
				while ($objDbRow = $objDbResult->GetNextRow()) {
					$objItem = TablePortfolioCategory::InstantiateDbRow($objDbRow, null, $strExpandAsArrayNodes, $objToReturn, $strColumnAliasArray);
					if ($objItem) {
						$objToReturn[] = $objItem;
					}
				}
			} else {
				while ($objDbRow = $objDbResult->GetNextRow())
					$objToReturn[] = TablePortfolioCategory::InstantiateDbRow($objDbRow, null, null, null, $strColumnAliasArray);
			}

			return $objToReturn;
		}



		///////////////////////////////////////////////////
		// INDEX-BASED LOAD METHODS (Single Load and Array)
		///////////////////////////////////////////////////
			
		/**
		 * Load a single TablePortfolioCategory object,
		 * by Id Index(es)
		 * @param integer $intId
		 * @param QQClause[] $objOptionalClauses additional optional QQClause objects for this query
		 * @return TablePortfolioCategory
		*/
		public static function LoadById($intId, $objOptionalClauses = null) {
			return TablePortfolioCategory::QuerySingle(
				QQ::AndCondition(
					QQ::Equal(QQN::TablePortfolioCategory()->Id, $intId)
				),
				$objOptionalClauses
			);
		}
			
		/**
		 * Load a single TablePortfolioCategory object,
		 * by CategoryId Index(es)
		 * @param integer $intCategoryId
		 * @param QQClause[] $objOptionalClauses additional optional QQClause objects for this query
		 * @return TablePortfolioCategory
		*/
		public static function LoadByCategoryId($intCategoryId, $objOptionalClauses = null) {
			return TablePortfolioCategory::QuerySingle(
				QQ::AndCondition(
					QQ::Equal(QQN::TablePortfolioCategory()->CategoryId, $intCategoryId)
				),
				$objOptionalClauses
			);
		}
			
		/**
		 * Load an array of TablePortfolioCategory objects,
		 * by ParentCategoryId Index(es)
		 * @param integer $intParentCategoryId
		 * @param QQClause[] $objOptionalClauses additional optional QQClause objects for this query
		 * @return TablePortfolioCategory[]
		*/
		public static function LoadArrayByParentCategoryId($intParentCategoryId, $objOptionalClauses = null) {
			// Call TablePortfolioCategory::QueryArray to perform the LoadArrayByParentCategoryId query
			try {
				return TablePortfolioCategory::QueryArray(
					QQ::Equal(QQN::TablePortfolioCategory()->ParentCategoryId, $intParentCategoryId),
					$objOptionalClauses);
			} catch (QCallerException $objExc) {
				$objExc->IncrementOffset();
				throw $objExc;
			}
		}

		/**
		 * Count TablePortfolioCategories
		 * by ParentCategoryId Index(es)
		 * @param integer $intParentCategoryId
		 * @return int
		*/
		public static function CountByParentCategoryId($intParentCategoryId) {
			// Call TablePortfolioCategory::QueryCount to perform the CountByParentCategoryId query
			return TablePortfolioCategory::QueryCount(
				QQ::Equal(QQN::TablePortfolioCategory()->ParentCategoryId, $intParentCategoryId)
			);
		}
			
		/**
		 * Load an array of TablePortfolioCategory objects,
		 * by Enable Index(es)
		 * @param string $strEnable
		 * @param QQClause[] $objOptionalClauses additional optional QQClause objects for this query
		 * @return TablePortfolioCategory[]
		*/
		public static function LoadArrayByEnable($strEnable, $objOptionalClauses = null) {
			// Call TablePortfolioCategory::QueryArray to perform the LoadArrayByEnable query
			try {
				return TablePortfolioCategory::QueryArray(
					QQ::Equal(QQN::TablePortfolioCategory()->Enable, $strEnable),
					$objOptionalClauses);
			} catch (QCallerException $objExc) {
				$objExc->IncrementOffset();
				throw $objExc;
			}
		}

		/**
		 * Count TablePortfolioCategories
		 * by Enable Index(es)
		 * @param string $strEnable
		 * @return int
		*/
		public static function CountByEnable($strEnable) {
			// Call TablePortfolioCategory::QueryCount to perform the CountByEnable query
			return TablePortfolioCategory::QueryCount(
				QQ::Equal(QQN::TablePortfolioCategory()->Enable, $strEnable)
			);
		}
			
		/**
		 * Load an array of TablePortfolioCategory objects,
		 * by RegisterDate Index(es)
		 * @param QDateTime $dttRegisterDate
		 * @param QQClause[] $objOptionalClauses additional optional QQClause objects for this query
		 * @return TablePortfolioCategory[]
		*/
		public static function LoadArrayByRegisterDate($dttRegisterDate, $objOptionalClauses = null) {
			// Call TablePortfolioCategory::QueryArray to perform the LoadArrayByRegisterDate query
			try {
				return TablePortfolioCategory::QueryArray(
					QQ::Equal(QQN::TablePortfolioCategory()->RegisterDate, $dttRegisterDate),
					$objOptionalClauses);
			} catch (QCallerException $objExc) {
				$objExc->IncrementOffset();
				throw $objExc;
			}
		}

		/**
		 * Count TablePortfolioCategories
		 * by RegisterDate Index(es)
		 * @param QDateTime $dttRegisterDate
		 * @return int
		*/
		public static function CountByRegisterDate($dttRegisterDate) {
			// Call TablePortfolioCategory::QueryCount to perform the CountByRegisterDate query
			return TablePortfolioCategory::QueryCount(
				QQ::Equal(QQN::TablePortfolioCategory()->RegisterDate, $dttRegisterDate)
			);
		}
			
		/**
		 * Load an array of TablePortfolioCategory objects,
		 * by UpdateDate Index(es)
		 * @param QDateTime $dttUpdateDate
		 * @param QQClause[] $objOptionalClauses additional optional QQClause objects for this query
		 * @return TablePortfolioCategory[]
		*/
		public static function LoadArrayByUpdateDate($dttUpdateDate, $objOptionalClauses = null) {
			// Call TablePortfolioCategory::QueryArray to perform the LoadArrayByUpdateDate query
			try {
				return TablePortfolioCategory::QueryArray(
					QQ::Equal(QQN::TablePortfolioCategory()->UpdateDate, $dttUpdateDate),
					$objOptionalClauses);
			} catch (QCallerException $objExc) {
				$objExc->IncrementOffset();
				throw $objExc;
			}
		}

		/**
		 * Count TablePortfolioCategories
		 * by UpdateDate Index(es)
		 * @param QDateTime $dttUpdateDate
		 * @return int
		*/
		public static function CountByUpdateDate($dttUpdateDate) {
			// Call TablePortfolioCategory::QueryCount to perform the CountByUpdateDate query
			return TablePortfolioCategory::QueryCount(
				QQ::Equal(QQN::TablePortfolioCategory()->UpdateDate, $dttUpdateDate)
			);
		}



		////////////////////////////////////////////////////
		// INDEX-BASED LOAD METHODS (Array via Many to Many)
		////////////////////////////////////////////////////




		//////////////////////////
		// SAVE, DELETE AND RELOAD
		//////////////////////////

		/**
		 * Save this TablePortfolioCategory
		 * @param bool $blnForceInsert
		 * @param bool $blnForceUpdate
		 * @return int
		 */
		public function Save($blnForceInsert = false, $blnForceUpdate = false) {
			// Get the Database Object for this Class
			$objDatabase = TablePortfolioCategory::GetDatabase();

			$mixToReturn = null;

			try {
				if ((!$this->__blnRestored) || ($blnForceInsert)) {
					// Perform an INSERT query
					$objDatabase->NonQuery('
						INSERT INTO `table_portfolio_category` (
							`category_id`,
							`parent_category_id`,
							`title_en`,
							`title_jp`,
							`keyword_en`,
							`keyword_jp`,
							`enable`,
							`register_date`,
							`update_date`
						) VALUES (
							' . $objDatabase->SqlVariable($this->intCategoryId) . ',
							' . $objDatabase->SqlVariable($this->intParentCategoryId) . ',
							' . $objDatabase->SqlVariable($this->strTitleEn) . ',
							' . $objDatabase->SqlVariable($this->strTitleJp) . ',
							' . $objDatabase->SqlVariable($this->strKeywordEn) . ',
							' . $objDatabase->SqlVariable($this->strKeywordJp) . ',
							' . $objDatabase->SqlVariable($this->strEnable) . ',
							' . $objDatabase->SqlVariable($this->dttRegisterDate) . ',
							' . $objDatabase->SqlVariable($this->dttUpdateDate) . '
						)
					');

					// Update Identity column and return its value
					$mixToReturn = $this->intId = $objDatabase->InsertId('table_portfolio_category', 'id');
				} else {
					// Perform an UPDATE query

					// First checking for Optimistic Locking constraints (if applicable)

					// Perform the UPDATE query
					$objDatabase->NonQuery('
						UPDATE
							`table_portfolio_category`
						SET
							`category_id` = ' . $objDatabase->SqlVariable($this->intCategoryId) . ',
							`parent_category_id` = ' . $objDatabase->SqlVariable($this->intParentCategoryId) . ',
							`title_en` = ' . $objDatabase->SqlVariable($this->strTitleEn) . ',
							`title_jp` = ' . $objDatabase->SqlVariable($this->strTitleJp) . ',
							`keyword_en` = ' . $objDatabase->SqlVariable($this->strKeywordEn) . ',
							`keyword_jp` = ' . $objDatabase->SqlVariable($this->strKeywordJp) . ',
							`enable` = ' . $objDatabase->SqlVariable($this->strEnable) . ',
							`register_date` = ' . $objDatabase->SqlVariable($this->dttRegisterDate) . ',
							`update_date` = ' . $objDatabase->SqlVariable($this->dttUpdateDate) . '
						WHERE
							`id` = ' . $objDatabase->SqlVariable($this->intId) . '
					');
				}

			} catch (QCallerException $objExc) {
				$objExc->IncrementOffset();
				throw $objExc;
			}

			// Update __blnRestored and any Non-Identity PK Columns (if applicable)
			$this->__blnRestored = true;


			// Return 
			return $mixToReturn;
		}

		/**
		 * Delete this TablePortfolioCategory
		 * @return void
		 */
		public function Delete() {
			if ((is_null($this->intId)))
				throw new QUndefinedPrimaryKeyException('Cannot delete this TablePortfolioCategory with an unset primary key.');

			// Get the Database Object for this Class
			$objDatabase = TablePortfolioCategory::GetDatabase();


			// Perform the SQL Query
			$objDatabase->NonQuery('
				DELETE FROM
					`table_portfolio_category`
				WHERE
					`id` = ' . $objDatabase->SqlVariable($this->intId) . '');
		}

		/**
		 * Delete all TablePortfolioCategories
		 * @return void
		 */
		public static function DeleteAll() {
			// Get the Database Object for this Class
			$objDatabase = TablePortfolioCategory::GetDatabase();

			// Perform the Query
			$objDatabase->NonQuery('
				DELETE FROM
					`table_portfolio_category`');
		}

		/**
		 * Truncate table_portfolio_category table
		 * @return void
		 */
		public static function Truncate() {
			// Get the Database Object for this Class
			$objDatabase = TablePortfolioCategory::GetDatabase();

			// Perform the Query
			$objDatabase->NonQuery('
				TRUNCATE `table_portfolio_category`');
		}

		/**
		 * Reload this TablePortfolioCategory from the database.
		 * @return void
		 */
		public function Reload() {
			// Make sure we are actually Restored from the database
			if (!$this->__blnRestored)
				throw new QCallerException('Cannot call Reload() on a new, unsaved TablePortfolioCategory object.');

			// Reload the Object
			$objReloaded = TablePortfolioCategory::Load($this->intId);

			// Update $this's local variables to match
			$this->intCategoryId = $objReloaded->intCategoryId;
			$this->intParentCategoryId = $objReloaded->intParentCategoryId;
			$this->strTitleEn = $objReloaded->strTitleEn;
			$this->strTitleJp = $objReloaded->strTitleJp;
			$this->strKeywordEn = $objReloaded->strKeywordEn;
			$this->strKeywordJp = $objReloaded->strKeywordJp;
			$this->strEnable = $objReloaded->strEnable;
			$this->dttRegisterDate = $objReloaded->dttRegisterDate;
			$this->dttUpdateDate = $objReloaded->dttUpdateDate;
		}



		////////////////////
		// PUBLIC OVERRIDERS
		////////////////////

				/**
		 * Override method to perform a property "Get"
		 * This will get the value of $strName
		 *
		 * @param string $strName Name of the property to get
		 * @return mixed
		 */
		public function __get($strName) {
			switch ($strName) {
				///////////////////
				// Member Variables
				///////////////////
				case 'Id':
					/**
					 * Gets the value for intId (Read-Only PK)
					 * @return integer
					 */
					return $this->intId;

				case 'CategoryId':
					/**
					 * Gets the value for intCategoryId (Unique)
					 * @return integer
					 */
					return $this->intCategoryId;

				case 'ParentCategoryId':
					/**
					 * Gets the value for intParentCategoryId 
					 * @return integer
					 */
					return $this->intParentCategoryId;

				case 'TitleEn':
					/**
					 * Gets the value for strTitleEn 
					 * @return string
					 */
					return $this->strTitleEn;

				case 'TitleJp':
					/**
					 * Gets the value for strTitleJp 
					 * @return string
					 */
					return $this->strTitleJp;

				case 'KeywordEn':
					/**
					 * Gets the value for strKeywordEn 
					 * @return string
					 */
					return $this->strKeywordEn;

				case 'KeywordJp':
					/**
					 * Gets the value for strKeywordJp 
					 * @return string
					 */
					return $this->strKeywordJp;

				case 'Enable':
					/**
					 * Gets the value for strEnable 
					 * @return string
					 */
					return $this->strEnable;

				case 'RegisterDate':
					/**
					 * Gets the value for dttRegisterDate (Not Null)
					 * @return QDateTime
					 */
					return $this->dttRegisterDate;

				case 'UpdateDate':
					/**
					 * Gets the value for dttUpdateDate 
					 * @return QDateTime
					 */
					return $this->dttUpdateDate;


				///////////////////
				// Member Objects
				///////////////////

				////////////////////////////
				// Virtual Object References (Many to Many and Reverse References)
				// (If restored via a "Many-to" expansion)
				////////////////////////////


				case '__Restored':
					return $this->__blnRestored;

				default:
					try {
						return parent::__get($strName);
					} catch (QCallerException $objExc) {
						$objExc->IncrementOffset();
						throw $objExc;
					}
			}
		}

				/**
		 * Override method to perform a property "Set"
		 * This will set the property $strName to be $mixValue
		 *
		 * @param string $strName Name of the property to set
		 * @param string $mixValue New value of the property
		 * @return mixed
		 */
		public function __set($strName, $mixValue) {
			switch ($strName) {
				///////////////////
				// Member Variables
				///////////////////
				case 'CategoryId':
					/**
					 * Sets the value for intCategoryId (Unique)
					 * @param integer $mixValue
					 * @return integer
					 */
					try {
						return ($this->intCategoryId = QType::Cast($mixValue, QType::Integer));
					} catch (QCallerException $objExc) {
						$objExc->IncrementOffset();
						throw $objExc;
					}

				case 'ParentCategoryId':
					/**
					 * Sets the value for intParentCategoryId 
					 * @param integer $mixValue
					 * @return integer
					 */
					try {
						return ($this->intParentCategoryId = QType::Cast($mixValue, QType::Integer));
					} catch (QCallerException $objExc) {
						$objExc->IncrementOffset();
						throw $objExc;
					}

				case 'TitleEn':
					/**
					 * Sets the value for strTitleEn 
					 * @param string $mixValue
					 * @return string
					 */
					try {
						return ($this->strTitleEn = QType::Cast($mixValue, QType::String));
					} catch (QCallerException $objExc) {
						$objExc->IncrementOffset();
						throw $objExc;
					}

				case 'TitleJp':
					/**
					 * Sets the value for strTitleJp 
					 * @param string $mixValue
					 * @return string
					 */
					try {
						return ($this->strTitleJp = QType::Cast($mixValue, QType::String));
					} catch (QCallerException $objExc) {
						$objExc->IncrementOffset();
						throw $objExc;
					}

				case 'KeywordEn':
					/**
					 * Sets the value for strKeywordEn 
					 * @param string $mixValue
					 * @return string
					 */
					try {
						return ($this->strKeywordEn = QType::Cast($mixValue, QType::String));
					} catch (QCallerException $objExc) {
						$objExc->IncrementOffset();
						throw $objExc;
					}

				case 'KeywordJp':
					/**
					 * Sets the value for strKeywordJp 
					 * @param string $mixValue
					 * @return string
					 */
					try {
						return ($this->strKeywordJp = QType::Cast($mixValue, QType::String));
					} catch (QCallerException $objExc) {
						$objExc->IncrementOffset();
						throw $objExc;
					}

				case 'Enable':
					/**
					 * Sets the value for strEnable 
					 * @param string $mixValue
					 * @return string
					 */
					try {
						return ($this->strEnable = QType::Cast($mixValue, QType::String));
					} catch (QCallerException $objExc) {
						$objExc->IncrementOffset();
						throw $objExc;
					}

				case 'RegisterDate':
					/**
					 * Sets the value for dttRegisterDate (Not Null)
					 * @param QDateTime $mixValue
					 * @return QDateTime
					 */
					try {
						return ($this->dttRegisterDate = QType::Cast($mixValue, QType::DateTime));
					} catch (QCallerException $objExc) {
						$objExc->IncrementOffset();
						throw $objExc;
					}

				case 'UpdateDate':
					/**
					 * Sets the value for dttUpdateDate 
					 * @param QDateTime $mixValue
					 * @return QDateTime
					 */
					try {
						return ($this->dttUpdateDate = QType::Cast($mixValue, QType::DateTime));
					} catch (QCallerException $objExc) {
						$objExc->IncrementOffset();
						throw $objExc;
					}


				///////////////////
				// Member Objects
				///////////////////
				default:
					try {
						return parent::__set($strName, $mixValue);
					} catch (QCallerException $objExc) {
						$objExc->IncrementOffset();
						throw $objExc;
					}
			}
		}

		/**
		 * Lookup a VirtualAttribute value (if applicable).  Returns NULL if none found.
		 * @param string $strName
		 * @return string
		 */
		public function GetVirtualAttribute($strName) {
			if (array_key_exists($strName, $this->__strVirtualAttributeArray))
				return $this->__strVirtualAttributeArray[$strName];
			return null;
		}



		///////////////////////////////
		// ASSOCIATED OBJECTS' METHODS
		///////////////////////////////





		////////////////////////////////////////
		// METHODS for SOAP-BASED WEB SERVICES
		////////////////////////////////////////

		public static function GetSoapComplexTypeXml() {
			$strToReturn = '<complexType name="TablePortfolioCategory"><sequence>';
			$strToReturn .= '<element name="Id" type="xsd:int"/>';
			$strToReturn .= '<element name="CategoryId" type="xsd:int"/>';
			$strToReturn .= '<element name="ParentCategoryId" type="xsd:int"/>';
			$strToReturn .= '<element name="TitleEn" type="xsd:string"/>';
			$strToReturn .= '<element name="TitleJp" type="xsd:string"/>';
			$strToReturn .= '<element name="KeywordEn" type="xsd:string"/>';
			$strToReturn .= '<element name="KeywordJp" type="xsd:string"/>';
			$strToReturn .= '<element name="Enable" type="xsd:string"/>';
			$strToReturn .= '<element name="RegisterDate" type="xsd:dateTime"/>';
			$strToReturn .= '<element name="UpdateDate" type="xsd:dateTime"/>';
			$strToReturn .= '<element name="__blnRestored" type="xsd:boolean"/>';
			$strToReturn .= '</sequence></complexType>';
			return $strToReturn;
		}

		public static function AlterSoapComplexTypeArray(&$strComplexTypeArray) {
			if (!array_key_exists('TablePortfolioCategory', $strComplexTypeArray)) {
				$strComplexTypeArray['TablePortfolioCategory'] = TablePortfolioCategory::GetSoapComplexTypeXml();
			}
		}

		public static function GetArrayFromSoapArray($objSoapArray) {
			$objArrayToReturn = array();

			foreach ($objSoapArray as $objSoapObject)
				array_push($objArrayToReturn, TablePortfolioCategory::GetObjectFromSoapObject($objSoapObject));

			return $objArrayToReturn;
		}

		public static function GetObjectFromSoapObject($objSoapObject) {
			$objToReturn = new TablePortfolioCategory();
			if (property_exists($objSoapObject, 'Id'))
				$objToReturn->intId = $objSoapObject->Id;
			if (property_exists($objSoapObject, 'CategoryId'))
				$objToReturn->intCategoryId = $objSoapObject->CategoryId;
			if (property_exists($objSoapObject, 'ParentCategoryId'))
				$objToReturn->intParentCategoryId = $objSoapObject->ParentCategoryId;
			if (property_exists($objSoapObject, 'TitleEn'))
				$objToReturn->strTitleEn = $objSoapObject->TitleEn;
			if (property_exists($objSoapObject, 'TitleJp'))
				$objToReturn->strTitleJp = $objSoapObject->TitleJp;
			if (property_exists($objSoapObject, 'KeywordEn'))
				$objToReturn->strKeywordEn = $objSoapObject->KeywordEn;
			if (property_exists($objSoapObject, 'KeywordJp'))
				$objToReturn->strKeywordJp = $objSoapObject->KeywordJp;
			if (property_exists($objSoapObject, 'Enable'))
				$objToReturn->strEnable = $objSoapObject->Enable;
			if (property_exists($objSoapObject, 'RegisterDate'))
				$objToReturn->dttRegisterDate = new QDateTime($objSoapObject->RegisterDate);
			if (property_exists($objSoapObject, 'UpdateDate'))
				$objToReturn->dttUpdateDate = new QDateTime($objSoapObject->UpdateDate);
			if (property_exists($objSoapObject, '__blnRestored'))
				$objToReturn->__blnRestored = $objSoapObject->__blnRestored;
			return $objToReturn;
		}

		public static function GetSoapArrayFromArray($objArray) {
			if (!$objArray)
				return null;

			$objArrayToReturn = array();

			foreach ($objArray as $objObject)
				array_push($objArrayToReturn, TablePortfolioCategory::GetSoapObjectFromObject($objObject, true));

			return unserialize(serialize($objArrayToReturn));
		}

		public static function GetSoapObjectFromObject($objObject, $blnBindRelatedObjects) {
			if ($objObject->dttRegisterDate)
				$objObject->dttRegisterDate = $objObject->dttRegisterDate->__toString(QDateTime::FormatSoap);
			if ($objObject->dttUpdateDate)
				$objObject->dttUpdateDate = $objObject->dttUpdateDate->__toString(QDateTime::FormatSoap);
			return $objObject;
		}




	}



	/////////////////////////////////////
	// ADDITIONAL CLASSES for QCubed QUERY
	/////////////////////////////////////

	class QQNodeTablePortfolioCategory extends QQNode {
		protected $strTableName = 'table_portfolio_category';
		protected $strPrimaryKey = 'id';
		protected $strClassName = 'TablePortfolioCategory';
		public function __get($strName) {
			switch ($strName) {
				case 'Id':
					return new QQNode('id', 'Id', 'integer', $this);
				case 'CategoryId':
					return new QQNode('category_id', 'CategoryId', 'integer', $this);
				case 'ParentCategoryId':
					return new QQNode('parent_category_id', 'ParentCategoryId', 'integer', $this);
				case 'TitleEn':
					return new QQNode('title_en', 'TitleEn', 'string', $this);
				case 'TitleJp':
					return new QQNode('title_jp', 'TitleJp', 'string', $this);
				case 'KeywordEn':
					return new QQNode('keyword_en', 'KeywordEn', 'string', $this);
				case 'KeywordJp':
					return new QQNode('keyword_jp', 'KeywordJp', 'string', $this);
				case 'Enable':
					return new QQNode('enable', 'Enable', 'string', $this);
				case 'RegisterDate':
					return new QQNode('register_date', 'RegisterDate', 'QDateTime', $this);
				case 'UpdateDate':
					return new QQNode('update_date', 'UpdateDate', 'QDateTime', $this);

				case '_PrimaryKeyNode':
					return new QQNode('id', 'Id', 'integer', $this);
				default:
					try {
						return parent::__get($strName);
					} catch (QCallerException $objExc) {
						$objExc->IncrementOffset();
						throw $objExc;
					}
			}
		}
	}

	class QQReverseReferenceNodeTablePortfolioCategory extends QQReverseReferenceNode {
		protected $strTableName = 'table_portfolio_category';
		protected $strPrimaryKey = 'id';
		protected $strClassName = 'TablePortfolioCategory';
		public function __get($strName) {
			switch ($strName) {
				case 'Id':
					return new QQNode('id', 'Id', 'integer', $this);
				case 'CategoryId':
					return new QQNode('category_id', 'CategoryId', 'integer', $this);
				case 'ParentCategoryId':
					return new QQNode('parent_category_id', 'ParentCategoryId', 'integer', $this);
				case 'TitleEn':
					return new QQNode('title_en', 'TitleEn', 'string', $this);
				case 'TitleJp':
					return new QQNode('title_jp', 'TitleJp', 'string', $this);
				case 'KeywordEn':
					return new QQNode('keyword_en', 'KeywordEn', 'string', $this);
				case 'KeywordJp':
					return new QQNode('keyword_jp', 'KeywordJp', 'string', $this);
				case 'Enable':
					return new QQNode('enable', 'Enable', 'string', $this);
				case 'RegisterDate':
					return new QQNode('register_date', 'RegisterDate', 'QDateTime', $this);
				case 'UpdateDate':
					return new QQNode('update_date', 'UpdateDate', 'QDateTime', $this);

				case '_PrimaryKeyNode':
					return new QQNode('id', 'Id', 'integer', $this);
				default:
					try {
						return parent::__get($strName);
					} catch (QCallerException $objExc) {
						$objExc->IncrementOffset();
						throw $objExc;
					}
			}
		}
	}

?>